package com.netbao.sys.vomapper;

import com.netbao.sys.model.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface RoleUserVoMapper {
    @Delete("DELETE FROM sys_user_role WHERE user_id=#{userid}")
    void delRole(Long userid);
    @Insert("INSERT INTO sys_user_role(user_id,role_id) SELECT #{userid},id FROM sys_role WHERE id IN(${roleIds})")
    void saveRole(String roleIds, Long userid);

//    @Select("SELECT #{userid} opid,r.id,cname,remark,IF(ur.user_id IS NULL,FALSE,TRUE) isdel FROM sys_role r LEFT JOIN sys_user_role ur " +
//            "ON(r.id=ur.role_id AND user_id=#{userid})")
    @Select("SELECT * FROM sys_role")
    List<Role> getRole();

    @Select("SELECT perms FROM sys_resources WHERE id IN(SELECT res_id FROM sys_role_res WHERE role_id IN(SELECT role_id FROM sys_user_role WHERE user_id=#{userid} ))")
    List<String> getperms(Integer userid);
}
